package com.uroad.jilinpda.activity;

import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;

import com.bumptech.glide.Glide;
import com.uroad.jilinpda.R;
import com.uroad.jilinpda.common.BaseActivity;
import com.uroad.jilinpda.widget.PhotoView;


import java.io.File;


/**
 * @创建者 wlw
 * @创建时间 2019/6/25 16:50
 * @描述
 */
public class PhotoViewActivity extends BaseActivity {
    private PhotoView photoView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setBaseContentLayoutWithoutTitle(R.layout.activity_photo_view);
        initView();
        initData();
    }

    private void initView() {
        photoView = (PhotoView) findViewById(R.id.photoview);
    }

    private void initData() {
        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            int imageRes = bundle.getInt("imageRes", 0);
            String imageUrl = bundle.getString("imageUrl", "");
            if (!TextUtils.isEmpty(imageUrl)) {
                if (imageUrl.startsWith("http"))
                    Glide.with(this).load(imageUrl).into(photoView);
                else
                    Glide.with(this).load(Uri.fromFile(new File(imageUrl))).into(photoView);
            }
            if (imageRes != 0) {
                photoView.setImageResource(imageRes);
            }
        }
    }
}
